package com.cykj.user.controller;

import com.cykj.common.core.utils.PageUtils;
import com.cykj.common.core.utils.poi.ExcelUtil;
import com.cykj.common.core.web.controller.BaseController;
import com.cykj.common.core.web.domain.AjaxResult;
import com.cykj.common.core.web.page.TableDataInfo;
import com.cykj.common.log.annotation.Log;
import com.cykj.common.log.enums.BusinessType;
import com.cykj.common.security.annotation.RequiresPermissions;
import com.cykj.user.domain.SystemCtComplaint;
import com.cykj.user.service.ISystemCtComplaintService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 用户申诉Controller
 *
 * @author 天才少年
 * @date 2025-08-19
 */
@RestController
@RequestMapping("/complaint")
public class SystemCtComplaintController extends BaseController
{
    @Autowired
    private ISystemCtComplaintService systemCtComplaintService;

    /**查询用户申诉列表*/
    @RequiresPermissions("system:complaint:list")
    @GetMapping("/list")
    public TableDataInfo list(SystemCtComplaint systemCtComplaint)
    {
        // 启动分页
        PageUtils.startPage();
        // 查询申诉列表
        List<SystemCtComplaint> list = systemCtComplaintService.selectSystemCtComplaintList(systemCtComplaint);
        // 封装分页结果
        return getDataTable(list);
    }

    /**导出用户申诉列表*/
    @RequiresPermissions("system:complaint:export")
    @Log(title = "用户申诉", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SystemCtComplaint systemCtComplaint) throws IOException
    {
        // 查询需要导出的数据
        List<SystemCtComplaint> list = systemCtComplaintService.selectSystemCtComplaintList(systemCtComplaint);
        // 导出Excel
        ExcelUtil<SystemCtComplaint> util = new ExcelUtil<>(SystemCtComplaint.class);
        util.exportExcel(response, list, "用户申诉数据");
    }

    /**获取用户申诉详细信息*/
    @RequiresPermissions("system:complaint:query")
    @GetMapping(value = "/{complaintId}")
    public AjaxResult getInfo(@PathVariable("complaintId") Long complaintId)
    {
        return success(systemCtComplaintService.selectSystemCtComplaintByComplaintId(complaintId));
    }

    /**新增用户申诉*/
    @RequiresPermissions("system:complaint:add")
    @Log(title = "用户申诉", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SystemCtComplaint systemCtComplaint)
    {
        return toAjax(systemCtComplaintService.insertSystemCtComplaint(systemCtComplaint));
    }

    /**修改用户申诉*/
    @RequiresPermissions("system:complaint:edit")
    @Log(title = "用户申诉", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SystemCtComplaint systemCtComplaint)
    {
        return toAjax(systemCtComplaintService.updateSystemCtComplaint(systemCtComplaint));
    }

    /**删除用户申诉*/
    @RequiresPermissions("system:complaint:remove")
    @Log(title = "用户申诉", businessType = BusinessType.DELETE)
    @DeleteMapping("/{complaintIds}")
    public AjaxResult remove(@PathVariable Long[] complaintIds)
    {
        return toAjax(systemCtComplaintService.deleteSystemCtComplaintByComplaintIds(complaintIds));
    }
}

